#project("OpenGL超级宝典")

include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}/GLTools/include 
    "${PROJECT_SOURCE_DIR}/freeglut-3.0.0/include" #注意这个变量依赖于上一级是否设置了project，否者还是想其他办法
)
link_directories(${PROJECT_SOURCE_DIR}/freeglut-3.0.0/build/lib/Release
                 ${PROJECT_SOURCE_DIR}/freeglut-3.0.0/build/lib/Debug                 
)

file (GLOB PLUGIN_PROJECTS  ${CMAKE_CURRENT_SOURCE_DIR}/[^.]* )
foreach (CURPROJECT ${PLUGIN_PROJECTS})	
	get_filename_component(PROJNAME ${CURPROJECT} NAME_WE)
	STRING( REGEX MATCH  ".*Chapter.*" var ${PROJNAME} )
	if( var)
		# message("遍历文件夹" ${var})
		file (GLOB Chapter_PROJECTS  ${CMAKE_CURRENT_SOURCE_DIR}/${var}/[^.]* )
		foreach (Chapter_ROJECT ${Chapter_PROJECTS})
		  file (GLOB Chapter_src  ${Chapter_ROJECT}/*.cpp ${Chapter_ROJECT}/*.c )
		  get_filename_component(executableName ${Chapter_ROJECT} NAME_WE)
		  add_executable( ${var}-${executableName}
			 ${Chapter_src}
		  )
          target_link_libraries(${var}-${executableName} debug GLToolsd  optimized GLTools  ) 
		  SET_PROPERTY(TARGET ${var}-${executableName} PROPERTY FOLDER ${var})
		endforeach()
	endif()

endforeach()

add_definitions(-DGLEW_BUILD)
file(GLOB header_files GLTools/include/*.h )
file(GLOB source_files GLTools/src/*.c GLTools/src/*.cpp )

add_library(GLTools 
    ${header_files}
    ${source_files}
)